<template>
    <div v-if="worksInfo.length != 0">
        <el-row class="swiper-painter-item">
            <el-card class="swiper-painter-cards" v-for="(workInfo,index) in worksInfo" :key="index">
                <button class="work-button" style="border: #ffffff" @click="workDetail(workInfo)">
                    <div v-if="workInfo.workFileType === 1"  @click="workDetail(workInfo)">
                        <img class="image" :src="imgUrl+workInfo.workFilename"/>
                    </div>
                    <div @click="workDetail(work)" v-else>
                        <video :poster="workInfo.poster" :controls="true" class="video_fo" :src="imgUrl+workInfo.workFilename"></video>
                    </div>
                </button>
                <div class="work-div">
                            <span class="painter-item-name">
                                {{workInfo.workName}}
                            </span>
                    </div>
                    <div class="introduction-motto">
                        <span class="author-span">
                            <img class="work-user-img" :src="imgUrl+workInfo.userImg">
                            <span class="author-span">
                                {{workInfo.username}}
                            </span>
                        </span>
                        <span class="star-span">
                            <i class="icon-favorites"></i>
                            {{workInfo.workLikesNums}}
                        </span>
                    </div>
            </el-card>
        </el-row>
        <!--页码-->
        <section class="stage-flex-container"
                 style="justify-content: center; align-items: stretch; align-self: auto;">
            <div class="is-darken el-pagination is-background">
                <el-pagination
                        background
                        layout="prev, pager, next"
                :total="worksInfo.length">
                </el-pagination>
            </div>
        </section>
    </div>
</template>

<script setup>
  import {getWorkInfoByKeyWord} from "@/assets/api/workInfoApi";
  import {useRoute, useRouter} from "vue-router";
  import {getCurrentInstance, onBeforeMount, ref} from "vue";

  const imgUrl = getCurrentInstance()?.appContext.config.globalProperties.$imgUrl
  const route = useRoute();
  const router = useRouter();
  const searchText = ref(route.query.searchText);
  const worksInfo = ref([{}]);
  const workImg = ref('');
  const workInfo = ref({});

  const getWorksInfo = () => {
    searchText.value = route.query.searchText;
    let data = {};
    data.workName = searchText.value;
    getWorkInfoByKeyWord('work_date', data).then((res) => {
      worksInfo.value = res.data.data;
    })
  };
  const workDetail = (work) => {
    router.push({path: '/workDetail', query: {id: work.workId}});
  };

  // watch:{
  //     '$route' (to, from){
  //         getWorksInfo();
  //     }
  // },
  onBeforeMount(() => {
    getWorksInfo();
  });

</script>

<style scoped>
    @import "../../assets/fonts/iconfont.css";
    .swiper-painter-item {
        overflow: hidden;
        border-radius: 4px;
        display: flex;
        flex-wrap: wrap;
    }
    .swiper-painter-cards {
        margin-top: 15px;
        height: 400px;
        margin-right: 10px;
        width: 300px;
    }
    .painter-item-name {
        max-width: 100px;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
        align-items: center;
        font-size: 14px;
        color: #333;
    }
    .introduction-motto {
        background-color: #ffffff;
        margin-top: 8px;
        font-size: 14px;
        word-break: break-all;
        overflow: hidden;
        text-overflow: ellipsis;
        text-align: justify;
        text-justify: inter-ideograph;
    }
    .image {
        width: 100%;
        height: 250px;
        display: block;
        margin: 0 auto
    }
    p {
        display: block;
        margin-block-start: 1em;
        margin-block-end: 1em;
        margin-inline-start: 0px;
        margin-inline-end: 0px;
    }
    .star-span {
        color: #adb3fb;
        float: right;
        background-color: #ffffff;
        margin-top: 20px;
    }
    .author-span {
        color: #777;
        font-size: 14px;
        max-width: 154px;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
        background-color: #ffffff;
    }
    .work-user-img {
        width: 55px;
        height: 55px;
        border-radius: 100%;
    }
    .work-div {
        background-color: #ffffff;
        margin-top: 20px;
        text-align: center;
    }
    .work-button {
        background-color: #ffffff;
        border: #fff;
        text-align: center;
    }
    .panel img {
        width: 300px;
        height: 400px;
        padding: 70px;
    }
    .stage-flex-container {
        display: -webkit-box;
        display: -ms-flexbox;
        display: flex;
    }
    .stage-flex-container {
        display: flex;
    }
    .modal-author__author-operator button {
        margin-left: 15px;
        width: 94px;
        height: 30px;
        padding: 4px 15px;
        border-radius: 20px;
        border: 1px solid transparent;
    }
    a {
        text-decoration: none;
    }
    .stage-flex-container {
        display: flex;
    }
    .artwork-modal ul {
        padding-left: 0;
        list-style: none;
    }
    .artwork-modal li {
        display: inline-block;
    }
    .comment-num span {
        color: #999;
        font-size: 14px;
    }
    .artwork-modal__operator i {
        color: #d8d8d8;
        font-size: 32px;
        margin-bottom: 5px;
    }
    .video_fo{
        position: relative;
        width: 283px;
        height: 200px;
        left: -20px;
    }
</style>
